package com.icss.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.icss.model.User;

public class UserDao extends BaseDao{
	//查询
	public static List<User> query(String sql,Object...obj){
		Connection conn = getConn();
		PreparedStatement ps = null;
		List<User> list = new ArrayList<>();
		ResultSet rs = null;
		try {
			ps = conn.prepareStatement(sql);
			for(int i = 0;i < obj.length;i++) {
				ps.setObject(i+1,obj[i]);
			}
			rs = ps.executeQuery();
			while(rs.next()) {
				User s = new User();
				s.setId(rs.getInt(1));
				s.setName(rs.getString(2));
				s.setPass(rs.getString(3));
				s.setTel(rs.getString(4));
				s.setType(rs.getInt(5));
				s.setTime(rs.getInt(6));
				list.add(s);
			}
		}catch (SQLException e) {
				System.out.println("sql语句异常"+e.getMessage());
		}finally {
			closeAll(conn, ps, rs);
		}
		return list;
	}
}
